package com.shanghai.shanghaielectric.UI.event;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.shanghai.shanghaielectric.R;
import com.shanghai.shanghaielectric.UI.FragmentTabAdapter_Main;

import java.util.ArrayList;
import java.util.List;


public class EventFragment extends Fragment {
	private RadioGroup eventrgs;
	public List<Fragment> eventfragments = new ArrayList<Fragment>();
	public View eventView;
	private EventErrorFragment eventError;
	private EventWarningFragment eventWarning;
	private int pause = 0;
	private RadioButton radio_event_warning;

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		System.out.println("Event____onAttach");
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		System.out.println("Event____onCreate");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		System.out.println("Event____onCreateView");
		eventView = inflater.inflate(R.layout.event_fragment, container,
				false);
		    
		
		pause = 0;
		radio_event_warning= (RadioButton) eventView.findViewById(R.id.radio_event_error);
		eventError = new EventErrorFragment();
		eventWarning = new EventWarningFragment();
		eventfragments.add(eventError);
		eventfragments.add(eventWarning);
		eventfragments.add(new EventOperationFragment());
		eventrgs = (RadioGroup) eventView
				.findViewById(R.id.tabs_event_rg);

		FragmentTabAdapter_Main tabAdapter = new FragmentTabAdapter_Main(
				this.getActivity(), eventfragments, R.id.tab_event_content,
				eventrgs);
		tabAdapter
				.setOnRgsExtraCheckedChangedListener(new FragmentTabAdapter_Main.OnRgsExtraCheckedChangedListener() {
					@Override
					public void OnRgsExtraCheckedChanged(RadioGroup radioGroup,
							int checkedId, int index) {
						System.out.println("Extra---- " + index
								+ " checked!!! ");
					}
				});

		return eventView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		System.out.println("Event____onActivityCreated");
	}

	@Override
	public void onStart() {
		super.onStart();
		System.out.println("Event____onStart");
	}

	@Override
	public void onResume() {
		super.onResume();
		if (pause == 1) {
			pause = 0;
			radio_event_warning.setChecked(true);
			if (eventError.isAdded()) {
				eventError.onResume(); // 启动目标tab的onResume()
			}
		}
		System.out.println("Event____onResume");
	}

	@Override
	public void onPause() {
		super.onPause();
		pause = 1;
		if (eventError.isAdded()) {
			eventError.onPause(); // 启动目标tab的onResume()
		}
		System.out.println("Event____onPause");
	}


	@Override
	public void onStop() {
		super.onStop();
		System.out.println("Event____onStop");
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		System.out.println("Event____onDestroyView");
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		System.out.println("Event____onDestroy");
	}

	@Override
	public void onDetach() {
		super.onDetach();
		System.out.println("Event____onDetach");
	}
}
